package app.common;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * Servlet Filter implementation class AppFilter
 */
public class AppFilter implements Filter {

	/**
	 * Default constructor.
	 */
	public AppFilter() {
		System.out.println("AppFilter()");
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	@Override
	public void init(FilterConfig fc) throws ServletException {
		System.out.println("AppFilter.init");
	}

	/**
	 * @see Filter#destroy()
	 */
	@Override
	public void destroy() {
		System.out.println("AppFilter.destroy");
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		// System.out.println("AppFilter.doFilter");
		req.setCharacterEncoding("UTF-8");
		// HttpServletRequest httpReq = (HttpServletRequest) req;
		// HttpServletResponse httpResp = (HttpServletResponse) resp;
		chain.doFilter(req, resp);
	}
}
